/********************
点击考核名称后的指标填报弹窗
** */
<template>
  <el-dialog
    width="80%"
    title="审核指标"
    :close-on-click-modal="false"
    :visible.sync="visible"
    top="8vh"
    @close="closeDialog()"
  >
    <el-form
      ref="dataForm"
      :model="dataForm"
      label-position="right"
      label-width="120px"
      @keyup.enter.native="dataFormSubmit()"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="考核名称" prop="name" style="width:60%">
            <span>{{dataForm.name}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="周期名称" prop="date" style="width:60%">
            <span>{{dataForm.period}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="考核时间" prop="sname" style="width:60%">
            <span>{{dataForm.assessBeginTime?dataForm.assessBeginTime.slice(0,10):""}}--{{dataForm.assessEndTime?dataForm.assessEndTime.slice(0,10):''}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="dataForm.type==0?'被考核人':'被考核机构'" style="width:60%;">
            <span v-for="it in dataForm.assessTarget" :key="it">{{it}},</span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
    <div style="height: 10px; border-top: 1px solid #b0bde2"></div>
    <div class="pull-right">
      <el-button type="primary" @click="agreeOrNot(0)">同意</el-button>
      <el-button type="primary" @click="agreeOrNot(1)">驳回</el-button>

    </div>
    </el-row>
    <el-row>
      <el-table
        style="width: 100%;margin-top:20px"
        :data="dataList"
        border
        stripe
        header-align="center"
      >
        <el-table-column type="index" width="55" label="序号"></el-table-column>
        <el-table-column prop="type" align="center" label="指标类别" width="140"></el-table-column>
        <el-table-column prop="name" align="center" label="指标名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="weight" align="center" label="权重(%)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="targetValue" align="center" label="目标值" show-overflow-tooltip></el-table-column>
        <el-table-column prop="finishValue" align="center" label="完成值" show-overflow-tooltip></el-table-column>
        <el-table-column prop="score" align="center" label="得分" show-overflow-tooltip></el-table-column>
        <el-table-column prop="formula" align="center" label="计算公式" show-overflow-tooltip></el-table-column>
        <el-table-column prop="unit" align="center" label="单位" show-overflow-tooltip></el-table-column>
        <el-table-column prop="completeValue" align="center" label="完成值获取方式" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="provideRealName"
          align="center"
          label="数据提供部门/人"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.isLiaison==0">{{scope.row.provideRealName}}</span>
            <span v-if="scope.row.isLiaison==1">{{scope.row.provideDeptName}}</span>
          </template>
        </el-table-column>
        <!--<el-table-column prop="itemIndex" align="center" label="排序号" show-overflow-tooltip></el-table-column>-->
        <el-table-column prop="state" align="center" label="状态" show-overflow-tooltip>
         <!-- <template slot-scope="scope">
            <span>{{scope.row.state==0?'拟定中':'拟定完成'}}</span>
          </template>
-->
          <template slot-scope="scope">
                <span v-if="scope.row.state == 0">未提交</span>
                <span v-else-if="scope.row.state == 1"
                >拟定中</span
                >
                <span v-else-if="scope.row.state == 2"
                >拟定审核中</span
                >
                <span v-else-if="scope.row.state == 3"
                >拟定已审核</span
                >
                <span v-else-if="scope.row.state == 4"
                >审核驳回</span
                >
                <span v-else-if="scope.row.state == 5"
                >结果填报中</span
                >
                <span v-else-if="scope.row.state == 6"
                >填报审核中</span
                >
                <span v-else-if="scope.row.state == 7"
                >填报审核驳回</span
                >
                <span v-else-if="scope.row.state == 8"
                >确认中</span
                >
                <span v-else-if="scope.row.state == 10"
                >已结束</span
                >
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="closeDialog()">返回</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  jgtbZbSubmit,
  targetAllFillIRTB,
  targetDetail
} from "@/api/dailyExamine/targetExamine/indicatorFormulation";
export default {
  data() {
    return {
      fatherData: {},
      dataList: [], //指标表格数据
      visible: false, //最外层弹窗显隐
      dataForm: {}, //表单对象
      id:"",
      taskId:"",
    };
  },
  created() {},
  methods: {
    // 同意or驳回
    agreeOrNot(type) {
        this.$confirm(`是否${type == 0 ? "同意" : "驳回"}选中数据`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        })
            .then(result => {
                console.log("同意or驳回");
                //提交
                if (type == 0) {
                    var params = {
                        rows: this.dataList,
                        id: this.id,
                        taskId:this.taskId,
                        type:0,
                    };
                    jgtbZbSubmit(params)
                        .then(res => {
                            this.visible = false;
                            this.$emit("refreshDataList");
                            this.closeDialog();
                            this.$message({
                                type: "success",
                                message: "提交成功!"
                            });

                        })
                        .catch(() => {
                            this.$message({
                                type: "error",
                                message: "提交失败!"
                            });
                            this.visible = false;
                            this.$emit("refreshDataList");
                            this.closeDialog();
                        });
                }
                //驳回
                if (type == 1) {
                    var params = {
                        rows: this.dataList,
                        id: this.id,
                        taskId:this.taskId,
                        type:1,
                    };
                    jgtbZbSubmit(params)
                        .then(res => {
                            this.visible = false;
                            this.$emit("refreshDataList");
                            this.closeDialog();
                            this.$message({
                                type: "success",
                                message: "驳回成功!"
                            });

                        })
                        .catch(() => {
                            this.$message({
                                type: "error",
                                message: "提交失败!"
                            });
                            this.visible = false;
                            this.$emit("refreshDataList");
                            this.closeDialog();
                        });
                }
            })
            .catch(err => {
                this.$message({
                    type: "info",
                    message: "已取消"
                });
            });
    },
    // 查询数据详情
    getDataDetail(id) {
      targetDetail(id)
        .then(r => {
          if (r.data.code == 0) {
            this.dataForm = r.data.data;
            this.dataForm.assessTarget = r.data.data.participantList.map(it => {
              return it.assessRealName;
            });
          } else {
            this.$message.error(r.data.msg);
          }
        })
        .catch(err => {});
    },
    // 查询需要自己填写的指标
    getNeedFillTarget(id,taskId) {
      targetAllFillIRTB(id,taskId)
        .then(r => {
          if (r.data.code == 0) {
            this.dataList = r.data.data;
          } else {
            this.$message.error(r.data.msg);
          }
        })
        .catch(err => {});
    },

    // 初始化
    init(data) {
      this.visible = true;
      this.fatherData = data;
      this.id = data.id;
      this.taskId =data.taskId;
      this.getDataDetail(data.id);
      this.getNeedFillTarget(data.id, data.taskId);
    },
    // 表单提交
    dataFormSubmit() {},
    // 关闭
    closeDialog() {
      this.visible = false;
      this.$emit("closeDialog");
    }
  }
};
</script>

<style lang="scss">
</style>
